<?php
/**
 * @author Radovan Dvorsky
 * @version 20100226
 */
require_once ('Zend/Form.php');

class Form_Commission_Add extends Zend_Form {
	
	private $_professors;
	
	public function init(){
		$cache = Zend_Registry::get('cache');
		$cacheName = My_Support::getCacheName('ProfessorController','fetchAll');
		
		if(!($this->_professors = $cache->load($cacheName))){
			$professorsMapper = new Db_Mapper_Professor();
			$this->_professors = $professorsMapper->fetchAll();

			$cache->save($this->_professors,$cacheName,array(get_class($professorsMapper)));
		}
	}
	
	public function __construct($options = null) {
		parent::__construct ($options);
		
		$this->setMethod('post');
		$this->addDecorator('fieldset',array('legend' => 'Vytvoriť komisiu'));
		
		$name = new Zend_Form_Element_Text('name');
		$name->setLabel('Meno komisie')
		->setRequired(true)
		->addFilter('StringTrim')		
		->addValidator('StringLength',false,array(3,25));
		
		$professors = new Zend_Form_Element_Multiselect('professors');
		$professors->setLabel('Členovia komisie');
		$professors->setAllowEmpty(false);
		$professors->setDescription("Pre viacnásobný výber použite klávesu CTRL");
		
		foreach($this->_professors as $professor){
			$professors->addMultiOption(
				$professor['pid'],
				$professor['lastname'] . ' ' . $professor['firstname']);
		}
		
		
		$submit = new Zend_Form_Element_Submit('commissionSubmit');
		$submit->setLabel('Pridať');
		
		$this->addElements(array($name,$professors));
		
	}
}

?>